package com.xtianzhuang.www.controller.login;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xtianzhuang.www.annotation.Log;
import com.xtianzhuang.www.annotation.Log.LogType;
import com.xtianzhuang.www.controller.BaseController;
import com.xtianzhuang.www.entity.User;
import com.xtianzhuang.www.entity.enums.Code;
import com.xtianzhuang.www.entity.response.UserResponse;
import com.xtianzhuang.www.service.UserInfoService;

/**
 * 
 * @ClassName: LoignController
 * @author : xtian.zhuang
 * @date 2018年6月5日 下午7:01:30
 *
 */
@Controller
@RequestMapping("/user")
public class LoignController extends BaseController {
	private static Logger logger = Logger.getLogger(BaseController.class);

	@Autowired
	private UserInfoService userService;

	@RequestMapping("/login")
	@ResponseBody
	@Log(type = LogType.LOGIN)
	public UserResponse dologin(User user) {
		logger.debug("== dologin start ==");
		UserResponse response = new UserResponse();
		try {
			if (userService.doUserLogin(user)) {
				// 更新
				response.setCode(Code.SUCCESS);
				response.setMessage("登录成功");
			} else {
				response.setCode(Code.SHOW_ERROR_MESSAGE_ONELINE);
				response.setMessage("账号或者密码错误");
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		logger.debug("== dologin end ==");
		return response;

	}
}
